//
//  CYSearchProblemView.m
//  DDSocial
//
//  Created by 阿帕 on 2018/9/22.
//  Copyright © 2018年 XY. All rights reserved.
//

#import "CYSearchProblemView.h"

@interface CYSearchProblemView ();

@property (strong , nonatomic)UITextField *textFiled;
@property (strong , nonatomic)UIButton *searchBtn;

@end

@implementation CYSearchProblemView

#pragma mark - Intial
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI{
    
    _textFiled = [[UITextField alloc] init];
    _textFiled.layer.masksToBounds = YES;
    _textFiled.layer.cornerRadius = 15;
    _textFiled.font = font(13);
    cutBorder(_textFiled, 1, @"#F2F2F2");
    _textFiled.backgroundColor = [UIColor cy_colorWithHexString:@"ffffff"];
    _textFiled.clearButtonMode = UITextFieldViewModeWhileEditing;
    _textFiled.keyboardType = UIKeyboardTypeDefault;
    _textFiled.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入文字搜索" attributes:@{NSForegroundColorAttributeName: Light_TextColor}];
    [_textFiled addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingDidEnd];
    _textFiled.clearButtonMode = UITextFieldViewModeWhileEditing;
    UIImageView *searchImage = [[UIImageView alloc]initWithFrame:CGRectMake(15, 7.5f, 15, 15)];
    searchImage.image = [UIImage imageNamed:@"gcy_img_applyOrder_search"];
    _textFiled.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
    _textFiled.leftViewMode = UITextFieldViewModeAlways;
    [_textFiled addSubview:searchImage];
    [self addSubview:_textFiled];
    
    _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    _searchBtn.tag = 150;
    [_searchBtn setTitle:@"搜索" forState:UIControlStateNormal];
    [_searchBtn setTitleColor:Orange_Color forState:UIControlStateNormal];
    _searchBtn.titleLabel.font = font(14);
    [_searchBtn addTarget:self action:@selector(searchBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_searchBtn];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [_textFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
//        make.right.equalTo(self).offset(-15);
        make.bottom.equalTo(self.mas_bottom).offset(-5);
        make.height.equalTo(@30);
        make.width.mas_equalTo(300*SP_Width);
    }];
    
    [_searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_textFiled.mas_right);
        make.centerY.equalTo(_textFiled);
        make.height.equalTo(@30);
        make.width.mas_equalTo(50*SP_Width);
    }];
}

- (void)textFieldChanged:(UITextField *)textField {
    
//    if (self.delegate && [self.delegate respondsToSelector:@selector(getKeywordInfo:)]) {
//
//        [self.delegate getKeywordInfo:textField.text];
//    }
}

- (void)searchBtnClick {
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(getKeywordInfo:)]) {
        
        [self.delegate getKeywordInfo:_textFiled.text];
    }
}

@end
